<?
$first_table=$_POST['FirstTable'];
$dbhost=$_POST['Host'];
$dbuser=$_POST['User'];
$dbpw=$_POST['Pass'];
$dbname=$_POST['DBName'];
$file=$_POST['File'];

if(!empty($first_table) && !empty($dbhost) && !empty($dbuser) && !empty($dbpw) && !empty($dbname))
{
	$db_host=$dbhost;
	$db_username=$dbuser;
	$db_password=$dbpw;
	$db_name=$dbname;
	
	include("class_mysql.php");

	$data=file_get_contents("../$file");

	$listtable=array("tblchat","tbluser");
	foreach($listtable as $key=>$table)
	{
		$data=preg_replace("((\s)([\W]*)([a-zA-Z0-9]*)(_".$table."))","$1$2".$first_table.$table,$data);
	}

	$dbsql->Restore($data);

	echo 'success!';
	
	$dbsql->saveconfigdb("includes/configdb.php",$db_host,$db_username,$db_password,$db_name,$first_table);
	exit;
}
?>

<form method=post>
<TABLE>
<tr>
	<td>File</td>
	<td><input name="File" /></td>
</tr>
<TR>
	<TD>Host</TD>
	<TD><input name=Host value="localhost"></TD>
</TR>
<TR>
	<TD>User</TD>
	<TD><input name=User></TD>
</TR>
<TR>
	<TD>Pass</TD>
	<TD><input type=password name=Pass></TD>
</TR>
<TR>
	<TD>DB Name</TD>
	<TD><input name=DBName></TD>
</TR>
<TR>
	<TD>First Table</TD>
	<TD><input name=FirstTable value="livesupport_"></TD>
</TR>
<TR>
	<TD></TD>
	<TD><input type=submit value=Install></TD>
</TR>

</TABLE>
</form>